home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 11 / Info-Mac_XI_Disc_1.cdr_ / Info-Mac XI Disc 1.cdr / Programs / Science & Math / MacEspresso 1.0 / espresso / gimpel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-26  |  2.2 KB  |  98 lines  |  [TEXT/R*ch]

  1. #include "mincov_int.h"
  2.  
  3.  
  4. /*
  5.  *  check for:
  6.  *
  7.  *        c1    c2    rest
  8.  *        --      --      ---
  9.  *         1     1    0 0 0 0        <-- primary row
  10.  *         1     0    S1        <-- secondary row
  11.  *         0       1    T1
  12.  *         0       1    T2
  13.  *         0       1    Tn
  14.  *         0       0      R
  15.  */
  16.  
  17. int
  18. gimpel_reduce(A, select, weight, lb, bound, depth, stats, best)
  19. sm_matrix *A;
  20. solution_t *select;
  21. int *weight;
  22. int lb;
  23. int bound;
  24. int depth;
  25. stats_t *stats;
  26. solution_t **best;
  27. {
  28.     register sm_row *prow, *save_sec;
  29.     register sm_col *c1, *c2;
  30.     register sm_element *p, *p1;
  31.     int c1_col_num, c2_col_num, primary_row_num, secondary_row_num;
  32.     int reduce_it; 
  33.  
  34.     reduce_it = 0;
  35.     for(prow = A->first_row; prow != 0; prow = prow->next_row) {
  36.     if (prow->length == 2) {
  37.         c1 = sm_get_col(A, prow->first_col->col_num);
  38.         c2 = sm_get_col(A, prow->last_col->col_num);
  39.         if (c1->length == 2) {
  40.         reduce_it = 1;
  41.         } else if (c2->length == 2) {
  42.         c1 = sm_get_col(A, prow->last_col->col_num);
  43.         c2 = sm_get_col(A, prow->first_col->col_num);
  44.         reduce_it = 1;
  45.         }
  46.         if (reduce_it) {
  47.         primary_row_num = prow->row_num;
  48.         secondary_row_num = c1->first_row->row_num;
  49.         if (secondary_row_num == primary_row_num) {
  50.             secondary_row_num = c1->last_row->row_num;
  51.         }
  52.         break;
  53.         }
  54.     }
  55.     }
  56.  
  57.     if (reduce_it) {
  58.     c1_col_num = c1->col_num;
  59.     c2_col_num = c2->col_num;
  60.     save_sec = sm_row_dup(sm_get_row(A, secondary_row_num));
  61.     sm_row_remove(save_sec, c1_col_num);
  62.  
  63.     for(p = c2->first_row; p != 0; p = p->next_row) {
  64.         if (p->row_num != primary_row_num) {
  65.         /* merge rows S1 and T */
  66.         for(p1 = save_sec->first_col; p1 != 0; p1 = p1->next_col) {
  67.             (void) sm_insert(A, p->row_num, p1->col_num);
  68.         }
  69.         }
  70.     }
  71.  
  72.     sm_delcol(A, c1_col_num);
  73.     sm_delcol(A, c2_col_num);
  74.     sm_delrow(A, primary_row_num);
  75.     sm_delrow(A, secondary_row_num);
  76.  
  77.     stats->gimpel_count++;
  78.     stats->gimpel++;
  79.     *best = sm_mincov(A, select, weight, lb-1, bound-1, depth, stats);
  80.     stats->gimpel--;
  81.  
  82.     if (*best != NIL(solution_t)) {
  83.         /* is secondary row covered ? */
  84.         if (sm_row_intersects(save_sec, (*best)->row)) {
  85.         /* yes, actually select c2 */
  86.         solution_add(*best, weight, c2_col_num);
  87.         } else {
  88.         solution_add(*best, weight, c1_col_num);
  89.         }
  90.     }
  91.  
  92.     sm_row_free(save_sec);
  93.     return 1;
  94.     } else {
  95.     return 0;
  96.     }
  97. }
  98.